package com.qf.kdxf.service.impl;

import com.qf.kdxf.service.TextIdentifyService;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

@Service
public class TextIdentifyServiceImpl implements TextIdentifyService {
    @Override
    public Map<String, String> constructHeader(String language, String location)
    {
        String X_CurTime = String.valueOf(System.currentTimeMillis() / 1000L);
        String param = "{\"language\":\"" + language + "\"" + ",\"location\":\""
                + location + "\"}";
        String X_Param = null;
        try {
            X_Param = new String(Base64.encodeBase64(param.getBytes("UTF-8")));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String apiKey = "你的apiKey";
        String X_Appid = "你的X_Appid";
        String X_CheckSum = DigestUtils.md5Hex(apiKey + X_CurTime + X_Param);
        Map<String, String> header = new HashMap();
        header.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
                header.put("X-Param", X_Param);
        header.put("X-CurTime", X_CurTime);
        header.put("X-CheckSum", X_CheckSum);
        header.put("X-Appid", X_Appid);
        return header;
    }
}
